#!/usr/bin/env python3

import os
import subprocess
import sys

import common

def main():
    return self.sh.run_cmd(
        [
            os.path.join(kwargs['qemu_src_dir'], 'scripts/simpletrace.py'), LF,
            os.path.join(kwargs['qemu_build_dir'], 'trace-events-all'), LF,
            os.path.join(kwargs['qemu_trace_file']), LF,
        ],
        cmd_file=os.path.join(kwargs['run_dir'], 'qemu-trace2txt'),
        out_file=kwargs['qemu_trace_txt_file'],
        show_stdout=False,
    )

if __name__ == '__main__':
    parser = self.get_argparse(argparse_args={
        'description': 'Convert a QEMU `-trace exec_tb` to text form.'
    })
    args = self.setup(parser)
    sys.exit(main())
